package com.mi.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.mi.bean.Manager;
import com.mi.service.impl.AjaxServiceImpl;
import com.mi.utils.MyUtils;

/**
 * ajax查询后台业务逻辑处理
 */
@WebServlet("/AjaxManagerMessageQueryAction")
public class AjaxManagerMessageQueryAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * 进行ajax响应
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 接收数据
		Manager managerA=MyUtils.convertFormData2Bean(request, Manager.class);
		//进行查询操作
		List<Manager> lstManager=MyUtils.getInstance(AjaxServiceImpl.class).queryLoginInfoByParams(managerA);
		System.out.println("从客户端请求获取的用户信息为："+lstManager);
		//借助第三方的工具将集合转换为json字符串【阿里巴巴的fastjson插件包】
		//将查询结果集list转换为json字符串
		String strJson=JSON.toJSONStringWithDateFormat(lstManager, "yyyy-MM-dd HH:mm:ss");
		//ajax响应
		//响应客户端的请求
		PrintWriter pw=response.getWriter();
		pw.write(strJson);
		pw.flush();
		
		pw.close();
	}

}
